﻿<%@ page import="model.q"%>
<%@ page import="model.a"%>
<%@ page import="dao.QDao"%>
<%@ page import="dao.ADao"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    ADao adao = new ADao();
    QDao qdao = new QDao();
    List<a> alist = new ArrayList<a>();
    List<q> qlist = new ArrayList<q>();
    if(qdao.findAll()!=null){
        try{
            qlist = qdao.findAll();
            System.out.print(qlist.get(0).getQuestion());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    if(request.getAttribute("qlist")!=null){
        qlist = (List<q>)request.getAttribute("qlist");
    }
    int i = 0;
    if(request.getParameter("i")!=null){
        i=Integer.parseInt(request.getParameter("i"));
    }
    int f = 1;
    if(qlist!=null&&i+4<qlist.size()){ f = i+4; }
    else if(qlist!=null){ f = qlist.size();}
%>

<!doctype html>
        <head>
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>问答</title>
                <link rel="shortcut icon" href="images/favicon.png" />
                <link rel='stylesheet' id='responsive-css-css' href='css/responsive5152.css?ver=1.0' type='text/css' media='all' />
                <link rel='stylesheet' id='pretty-photo-css-css'  href='js/prettyphoto/prettyPhotoaeb9.css?ver=3.1.4' type='text/css' media='all' />
                <link rel='stylesheet' id='main-css-css' href='css/main5152.css?ver=1.0' type='text/css' media='all' />
                <link rel='stylesheet' id='custom-css-css' href='css/custom5152.html?ver=1.0' type='text/css' media='all' />
                <link rel="stylesheet" type="text/css" href="bootstrap/css/htmleaf-demo.css">
                <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
                <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-theme.min.css" />
                <link rel="stylesheet" href="bootstrap/css/gallery-grid.css">
                <script type="text/javascript" charset="utf-8"></script>
        </head>
        <body>
        <jsp:include page="navBar.jsp"/>
        <div class="container">
        <div class="row clearfix">
                <div class="col-md-12 column">
                    <div class="search-area-wrapper">
                        <ul class="breadcrumb">
                            <li>
                                <a href="index.jsp">&nbsp首页&nbsp</a>
                            </li>
                            <li>
                                <a href="#">&nbsp社区&nbsp</a>
                            </li>
                            <li class="active">
                                &nbsp问题列表&nbsp
                            </li>
                        </ul>
                        <div class="search-area container">
                            <h3 class="search-header">问答专栏</h3>
                            <p class="search-tag-line">如果你有问题，可以在这里输入你的问题来查找!</p>

                            <form id="search-form" class="search-form clearfix" method="get" action="searchController" autocomplete="off">
                                <input type="text" id="s" name="s" size="80" style="height:46px;" placeholder="在这里输入你的问题" />
                                <input class="search-btn" type="submit" value="查找" />
                                <div id="search-error-container"></div>
                            </form>
                        </div>
                    </div>
                </div>
        </div>

        </div>>
                <!-- Start of Page Container -->


            <div class="container" class="bg-primary">
                <div class="row">
                    <div class="col-md-12 column">
                        <div class="color1234567">
                                    <!-- start of page content -->
                                        <div class="col-md-8 column">
                                            <br><br>
                                            <%if(qlist==null){%>
                                            <article class="format-standard type-post hentry clearfix">
                                                <header class="clearfix">
                                                    <h3 class="post-title">
                                                        <a class="readmore-link" href="#">暂时还没有人提出问题</a>
                                                    </h3>

                                                    <div class="post-meta clearfix">
                                                        <span class="date">无</span>
                                                        <span class="comments"><a href="" title="Comment on Integrating WordPress with Your Website">0 Comments</a></span>
                                                        <span class="like-count">0</span>
                                                    </div>
                                                </header>
                                                <p>无内容</p>
                                            </article>
                                            <%}else{%>
                                            <%for(;i<f;i++){ alist=adao.findById(qlist.get(i).getIdQA());%>
                                                <article class="format-standard type-post hentry clearfix">
                                                        <header class="clearfix">
                                                                <h3 class="post-title">
                                                                    <a class="readmore-link" href="wenda.jsp?idqa=<%=qlist.get(i).getIdQA()%>"> <%=qlist.get(i).getQuestion()%> </a>
                                                                </h3>

                                                                <div class="post-meta clearfix">
                                                                        <span class="date"><%=qlist.get(i).getQuestionTime()%></span>
                                                                        <span class="comments"><a href="#" title="Comment on Integrating WordPress with Your Website"><%=alist.size()%> Comments</a></span>
                                                                        <span class="like-count">0</span>
                                                                </div>
                                                        </header>
                                                    <p><%=qlist.get(i).getQuestionContext()%></p>
                                                </article><br><br>
                                            <%}%>
                                            <%}%>
                                            <%if(qlist!=null&&qlist.size()<=4){%>
                                            <%}else if(qlist!=null){%>
                                            <%int t = qlist.size()/4+1;%>
                                            <ul class="pagination">
                                              <%for(int a=1;a<=t;a++){%>
                                                  <li>
                                                      <a href="qa1.jsp?i=<%=4*(a-1)%>"><%=a%></a>
                                                  </li>
                                              <%}%>
                                            </ul>
                                            <%}%>

                                            <div class="row clearfix">
                                                <div class="col-md-12 column">
                                                    <br><br>
                                                    <form role="form" action="QController">
                                                        <div class="form-group">
                                                            <label>主题</label><input type="text" class="form-control" name="question" placeholder="主题"/>
                                                        </div>
                                                        <div class="form-group">
                                                            <label >提问内容</label><br><textarea cols=98 rows=9 name="context" placeholder="请在这里输入主要内容"></textarea>
                                                        </div>
                                                        <input type="submit" value="发表"/>
                                                        <%if (request.getAttribute("error")!= null){%>
                                                        <strong>警告！</strong><span class="tips-text"><%= request.getAttribute("error")%></span>
                                                        <%}%>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- end of page content -->


                                        <!-- start of sidebar -->
                                        <div class="col-md-4 column">
                                                <section class="widget">
                                                        <h3 class="title">广告</h3>
                                                        <img alt="140x140" src="bootstrap/images/旅游图片.jpg" height=390 width=300/><br>
                                                        <img alt="140x140" src="bootstrap/images/问答图片1.jpg" height=390 width=300/>
                                                </section>
                                        </div>
                        </div><!-- end of sidebar -->
                    </div>
                </div>
                </div>
        <br><br><br>
                <!-- End of Page Container -->
        <div class="related">
            <jsp:include page="footer.jsp"/></div>


        </body>
</html>
